package com.hq.ims.home.controller;

import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.service.other.BaiduMapService;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yinzhangxiao
 * @date 2024/11/13 10:16
 * @ClassName BaiduMapApiController
 **/
@Api(tags = "百度地图api")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_PUBLIC_URL_PREFIX + "/map")
public class BaiduMapApiController {

    @Resource
    private BaiduMapService baiduMapService;

    @ApiOperation(value = "根据关键字查询地址", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getPlace", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo getPlace(
            @GetJsonValue(zh = "关键字") String keyWord,
            @GetJsonValue(zh = "城市") String region,
            @GetJsonValue(zh = "经纬度", required = false) String location
    ) throws Exception {
        return ReturnVo.buildSuccess(baiduMapService.getPlace(keyWord, region, location));
    }

    @ApiOperation(value = "根据地址查询经纬度", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getPlaceByAddress", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo getPlaceByAddress(
            @GetJsonValue(zh = "地址") String address,
            @GetJsonValue(zh = "城市", required = false) String city
    ) throws Exception {
        return ReturnVo.buildSuccess(baiduMapService.getPlaceByAddress(address, city));
    }

    @ApiOperation(value = "根据经纬度查询地址", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getPlaceByLocation", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo getPlaceByLocation(
            @GetJsonValue(zh = "经度") String lng,
            @GetJsonValue(zh = "维度") String lat
    ) throws Exception {
        return ReturnVo.buildSuccess(baiduMapService.getPlaceByLocation(lng, lat));
    }
}
